import Vue from 'vue'
import dayjs from 'dayjs'

Vue.filter('date', value => {
  var dayjsValue = dayjs(value)
  if (dayjsValue.isValid()) {
    return dayjsValue.format('YYYY-MM-DD')
  } else {
    return ''
  }
})

Vue.filter('dateMini', value => {
  var dayjsValue = dayjs(value)
  if (dayjsValue.isValid()) {
    return dayjsValue.format('YY/MM/DD')
  } else {
    return ''
  }
})

Vue.filter('datetime', value => {
  var dayjsValue = dayjs(value)
  if (dayjsValue.isValid()) {
    return dayjsValue.format('YYYY-MM-DD HH:mm:ss')
  } else {
    return ''
  }
})
Vue.filter('datetimeShort', value => {
  var dayjsValue = dayjs(value)
  if (dayjsValue.isValid()) {
    return dayjsValue.format('YYYY-MM-DD HH:mm')
  }
})
Vue.filter('datetimeMini', value => {
  var dayjsValue = dayjs(value)
  if (dayjsValue.isValid()) {
    return dayjsValue.format('MM-DD HH:mm')
  }
})

Vue.filter('year', value => {
  var dayjsValue = dayjs(value)
  if (dayjsValue.isValid()) {
    return dayjsValue.format('YYYY')
  } else {
    return ''
  }
})

Vue.filter('month', value => {
  var dayjsValue = dayjs(value)
  if (dayjsValue.isValid()) {
    return dayjsValue.format('MM')
  } else {
    return ''
  }
})

Vue.filter('day', value => {
  var dayjsValue = dayjs(value)
  if (dayjsValue.isValid()) {
    return dayjsValue.format('DD')
  } else {
    return ''
  }
})

Vue.filter('hour', value => {
  var dayjsValue = dayjs(value)
  if (dayjsValue.isValid()) {
    return dayjsValue.format('HH')
  } else {
    return ''
  }
})

Vue.filter('minute', value => {
  var dayjsValue = dayjs(value)
  if (dayjsValue.isValid()) {
    return dayjsValue.format('mm')
  } else {
    return ''
  }
})

Vue.filter('second', value => {
  var dayjsValue = dayjs(value)
  if (dayjsValue.isValid()) {
    return dayjsValue.format('ss')
  } else {
    return ''
  }
})

Vue.filter('time', value => {
  var dayjsValue = dayjs(value)
  if (dayjsValue.isValid()) {
    return dayjsValue.format('HH:mm')
  } else {
    return ''
  }
})

Vue.filter('timeFormat', value => {
  var dayjsValue = dayjs(value)
  if (dayjsValue.isValid()) {
    return dayjsValue.format('HH:mm:ss')
  } else {
    return ''
  }
})

Vue.filter('reportTimeFormat', value => {
  var dayjsValue = dayjs(value)
  if (dayjsValue.isValid()) {
    return dayjsValue.format('HH时mm分')
  }
})

Vue.filter('reportDateFormat', value => {
  var dayjsValue = dayjs(value)
  if (dayjsValue.isValid()) {
    return dayjsValue.format('MM月DD日 HH时mm分')
  }
})
Vue.filter('reportDateLongFormat', value => {
  var dayjsValue = dayjs(value)
  if (dayjsValue.isValid()) {
    return dayjsValue.format('YYYY年MM月DD日 HH时mm分')
  }
})

Vue.filter('dailyFormat', value => {
  var dayjsValue = dayjs(value)
  if (dayjsValue.isValid()) {
    return dayjsValue.format('YYYY年MM月DD日HH时mm分')
  }
})

// br转化\n
Vue.filter('brFormat', value => {
  return value.replace(/＜br＞/g, '\n').replace(/<br\/>/g, '\n').replace(/<br>/g, '\n')
})

const brFormat = function(value) {
  return value.replace(/＜br＞/g, '\n').replace(/<br\/>/g, '\n').replace(/<br>/g, '\n')
}

// 工作票安全等级
const safeLevelList = ['', '一', '二', '三', '四', '五']
Vue.filter('safeLevel', value => {
  return value < safeLevelList.length ? safeLevelList[value] : ''
})

// 设备项目枚举
const deviceType = {
  JCW_DEVICE: '接触网设备',
  ELE_DEVICE: '电力设备',
  DISPATCH_DEVICE: '变配电设备',
  SUPPLY_DEVICE: '供水设备',
  PATH_DEVICE: '通道设备'
}
Vue.filter('deviceType', value => {
  return value ? deviceType[value] : ''
})

// 料具分类属性 0:工具 1：材料 2：劳保3：终端设备
const toolType = ['工具', '材料', '劳保', '终端设备']
Vue.filter('toolType', value => {
  return value < toolType.length ? toolType[value] : ''
})

// 计划状态（0-初始化 1-已下发、2-已接收、3-已出动、4-抢修中、5-已完成、6-已终止）
const planStatus = ['初始化', '已下发', '已接收', '已出动', '抢修中', '已完成', '已终止']
Vue.filter('planStatus', value => {
  return value < planStatus.length ? planStatus[value] : ''
})

// 计划类型1:检修计划 2：施工计划，3：天窗计划 4：点外计划 5：巡视计划
const planType = ['全部', '检修计划', '施工计划', '天窗计划', '点外计划', '巡视计划']
Vue.filter('planType', value => {
  return value < planType.length ? planType[value] : ''
})

// 线岔类型（1.单开,2.对开,3.复式交分,4.交叉渡线岔）
const wireType = ['无', '单开', '对开', '复式交分', '交叉渡线岔']
Vue.filter('wireType', value => {
  return value < wireType.length ? wireType[value] : ''
})

// 高铁线岔类型（1.支柱位于正线侧,2.支柱位于侧线侧）
const wireTypeGT = [' ', '支柱位于正线侧', '支柱位于侧线侧']
Vue.filter('wireTypeGT', value => {
  return value < wireTypeGT.length ? wireTypeGT[value] : ''
})

// 消息类型（1-指挥令、2-现场消息）
const messageType = [' ', '指挥令', '现场消息']
Vue.filter('messageType', value => {
  return value < messageType.length ? messageType[value] : ''
})

// 关键岗位 0-作业指挥长 1-抢修领导人 2-值班领导
const positionType = ['作业指挥长', '抢修领导人', '值班领导']
Vue.filter('positionType', value => {
  return value < positionType.length ? positionType[value] : ''
})

const handleStatus = ['未处理', '已处理']
Vue.filter('handleStatus', value => {
  return value < handleStatus.length ? handleStatus[value] : ''
})

// 故障处理状态
const troubleStatus = ['处理中', '已完成', '已定责']
Vue.filter('troubleStatus', value => {
  return value < troubleStatus.length ? troubleStatus[value] : ''
})

/**
 * 公里标格式化（123.456 -> K123+456）
 */
Vue.filter('km', value => {
  if (value) {
    return ('K' + value.toFixed(3)).replace('.', '+')
  } else {
    return 'K0+0'
  }
})

// 检修台账类型
const repairType = [
  {
    typeId: 'JCWB_RR_ANCHORAGE_JOINT',
    typeName: '锚段关节检修记录',
    path: '/pspc/ledger-detail/anchor-joint',
    componentLedgerName: 'anchor-joint'
  },
  {
    typeId: 'JCWB_RR_ARRESTER',
    typeName: '避雷器检修记录',
    path: '/pspc/ledger-detail/arrester',
    componentLedgerName: 'arrester'
  },
  {
    typeId: 'JCWB_RR_CABLE_ACCESSORY',
    typeName: '接触网27.5kV电缆及附件检修记录',
    path: '/pspc/ledger-detail/accessory',
    componentLedgerName: 'accessory'
  },
  {
    typeId: 'JCWB_RR_MID_POINT_ANCHOR',
    typeName: '中心锚结检修记录',
    path: '/pspc/ledger-detail/central-anchor',
    componentLedgerName: 'central-anchor'
  },
  {
    typeId: 'JCWB_RR_COMPONENT_PHASE',
    typeName: '器件式分相绝缘器检修记录',
    path: '/pspc/ledger-detail/component-phase',
    componentLedgerName: 'component-phase'
  },
  {
    typeId: 'JCWB_RR_INTERSECTING_FORK',
    typeName: '交叉线岔检修记录',
    path: '/pspc/ledger-detail/fork',
    componentLedgerName: 'fork'
  },
  {
    typeId: 'JCWB_RR_INSULATION_TEST',
    typeName: '重污区段领示点绝缘部件附盐密度值检测记录',
    path: '/pspc/ledger-detail/heavy-pollution',
    componentLedgerName: 'heavy-pollution'
  },
  {
    typeId: 'JCWB_RR_HYDRAULIC_COMPENSATION',
    typeName: '液压补偿装置检修记录',
    path: '/pspc/ledger-detail/hydraulic-compensate',
    componentLedgerName: 'hydraulic-compensate'
  },
  {
    typeId: 'JCWB_RR_INDUCTOR',
    typeName: '自动过分相地面磁感应器检修记录',
    path: '/pspc/ledger-detail/inductor',
    componentLedgerName: 'inductor'
  },
  {
    typeId: 'JCWB_RR_SECTION_INSULATOR',
    typeName: '分段绝缘器检修记录',
    path: '/pspc/ledger-detail/insulator',
    componentLedgerName: 'insulator'
  },
  {
    typeId: 'JCWB_RR_ARTICULAR_PHASE',
    typeName: '关节式分相检修记录',
    path: '/pspc/ledger-detail/joint-splitphase',
    componentLedgerName: 'joint-split-phase'
  },
  {
    typeId: 'JCWB_RR_LOOP_THERMOMETRIC',
    typeName: '接触网主导电回路电气接续点测温记录',
    path: '/pspc/ledger-detail/loop-thermometer',
    componentLedgerName: 'loop-thermometer'
  },
  {
    typeId: 'JCWB_RR_NON_CROSS_GT',
    typeName: '高速铁路无交叉线岔检修记录',
    path: '/pspc/ledger-detail/NonCrossGT',
    componentLedgerName: 'NonCrossGT'
  },
  {
    typeId: 'JCWB_RR_NON_CROSS_PT',
    typeName: '普速铁路无交叉线岔检修记录',
    path: '/pspc/ledger-detail/NonCrossPT',
    componentLedgerName: 'NonCrossPT'
  },
  {
    typeId: 'JCWB_RR_OVERALL_INSPECTION',
    typeName: '全面检修',
    path: '/pspc/ledger-detail/overall',
    componentLedgerName: 'overall'
  },
  {
    typeId: 'JCWB_RR_RAIL_SURFACE',
    typeName: '接触网轨面标准线检测检修记录',
    path: '/pspc/ledger-detail/rail-surface',
    componentLedgerName: 'rail-surface'
  },
  {
    typeId: 'JCWB_RR_RATCHET_COMPENSATION',
    typeName: '棘轮补偿装置检修记录',
    path: '/pspc/ledger-detail/ratchet-device',
    componentLedgerName: 'ratchet-device'
  },
  {
    typeId: 'JCWB_RR_PULLEY_COMPENSATION',
    typeName: '滑轮补偿装置检修记录',
    path: '/pspc/ledger-detail/roller-skating-device',
    componentLedgerName: 'roller-skating-device'
  },
  {
    typeId: 'JCWB_RR_SOFT_HARD_STRADDLE',
    typeName: '软（硬）横跨检修记录',
    path: '/pspc/ledger-detail/ry-goacross',
    componentLedgerName: 'ry-goacross'
  },
  {
    typeId: 'JCWB_RR_SPRING_COMPENSATION',
    typeName: '弹簧补偿装置检修记录',
    path: '/pspc/ledger-detail/spring-compensation',
    componentLedgerName: 'spring-compensation'
  },
  {
    typeId: 'JCWB_RR_ISOLATING_SWITCH',
    typeName: '隔离（负荷）开关检修记录',
    path: '/pspc/ledger-detail/switch',
    componentLedgerName: 'divide-switch'
  },
  {
    typeId: 'JCWB_RR_CONTACT_WIRE_ABRASION',
    typeName: '接触线（承力索）磨耗和损伤记录',
    path: '/pspc/ledger-detail/wire-abrasion',
    componentLedgerName: 'wire-abrasion'
  },
  {
    typeId: 'JCWB_RR_NON_CROSS_HANG',
    typeName: '带辅助悬挂的无交叉线岔检修记录',
    path: '/pspc/ledger-detail/non-cross-hang',
    componentLedgerName: 'non-cross-hang'
  },
  {
    typeId: 'JCWB_RR_CONTACT_WIRE_POSITION',
    typeName: '接触线位置检测检修实测值记录',
    path: '/pspc/ledger-detail',
    componentLedgerName: 'ledger-detail'
  },
  {
    typeId: 'JCWB_RR_PATROL_RECORD',
    typeName: '巡视检查记录',
    path: '/pspc/ledger-detail',
    componentLedgerName: 'ledger-detail'
  },
  {
    typeId: 'JCWB_RR_SECTION_INSULATOR_WJTL',
    typeName: '吴江天龙分段绝缘器图示检修记录',
    path: '/pspc/ledger-detail',
    componentLedgerName: 'ledger-detail'
  },
  {
    typeId: 'JCWB_RR_SECTION_INSULATOR_XMZB',
    typeName: '西门子、保德利分段绝缘器图示检修记录',
    path: '/pspc/ledger-detail',
    componentLedgerName: 'ledger-detail'
  }
]

function getRepairType(repairId) {
  var resArrray = repairType.filter(item => item.typeId === repairId)
  return resArrray[0]
}

// 重合闸状态
const reclosureConditions = ['复电失败', '复电成功', '强送成功', '强送失败']
Vue.filter('reclosureCondition', value => {
  return value < reclosureConditions.length ? reclosureConditions[value] : ''
})

// 故障定性
const faultQualitative = ['非事故', '事故']
Vue.filter('faultQualitative', value => {
  return value < faultQualitative.length ? faultQualitative[value] : ''
})

export { repairType, getRepairType, brFormat }

// 设备问题库状态
const problemStatus = { 0: '未处理', 1: '已处理', 2: '已销号' }
Vue.filter('problemStatus', value => {
  var result = ''
  if (problemStatus[value]) {
    result = problemStatus[value]
  }
  return result
})
